<template>
  <div class="row4">
    <label style="margin-left: 10px"
      >注：蓝色指标数据来源为调查问卷，红色指标为多个数据综合计算,
      <span style="color: #7e2030; font-weight: bold">点击指标名称查看详细</span>

      <!--        <button @click="dowenloadexel" style="color: blue">&nbsp;&nbsp; 导出Exel文件</button>-->
    </label>
    <div style="margin-left: 35px; align-items: center; display: flex">
      <el-button type="primary" @click="dowenloadexel">导出Excel</el-button>
      <el-button type="primary" @click="quanzhong">查看指标权重</el-button>
    </div>
  </div>

  <div class="row row3" id="tableDataLoding">
    <el-table
      v-loading="loading"
      :data="tableData"
      height="250"
      border
      style="width: 100%; height: 100%"
    >
      <el-table-column
        fixed
        header-align="center"
        align="center"
        type="index"
        width="50"
        label="序号"
      >
      </el-table-column>

      <el-table-column
        fixed
        header-align="center"
        align="center"
        prop="school"
        width="130"
        label="学校"
      >
      </el-table-column>

      <el-table-column
        fixed
        header-align="center"
        align="center"
        prop="major"
        width="90"
        label="专业"
      >
        <template #header>
          <el-popover :width="zbsmwidth" class="box-item" title="说明" placement="bottom">
            <template #default>
              <div style="white-space: pre-line">{{ zbsm000 }}</div>
            </template>

            <template #reference>
              <el-span>专业</el-span>
            </template>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        sortable
        fixed
        header-align="center"
        align="center"
        prop="fzzspjf"
        width="90"
        label="发展指数"
      >
        <template #header>
          <el-popover :width="zbsmwidth" class="box-item" title="说明" placement="bottom">
            <template #default>
              <div style="white-space: pre-line">{{ zbsm0 }}</div>
            </template>

            <template #reference>
              <el-span>发展指数</el-span>
            </template>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column
        fixed
        header-align="center"
        align="center"
        prop="yxzbs"
        width="90"
        label="有效指标数"
      >
        <template #header>
          <el-popover :width="zbsmwidth" class="box-item" title="说明" placement="bottom">
            <template #default>
              <div style="white-space: pre-line">{{ zbsm00 }}</div>
            </template>

            <template #reference>
              <el-span>有效指标数</el-span>
            </template>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column label="生源状态" header-align="center" align="center">
        <el-table-column label="生源水平" header-align="center" align="center">
          <el-table-column
            header-align="center"
            align="center"
            prop="lqfs"
            label="录取分数"
            width="90"
          >
            <template #header>
              <router-link
                to="lqfs"
                @click="handleAddTag({ path: '/home/lqfs', name: 'lqfs', title: '录取分数' })"
              >
                <el-popover
                  :width="zbsmwidth"
                  class="box-item"
                  title="说明"
                  :content="zbsm1"
                  placement="bottom"
                >
                  <template #reference>
                    <span style="color: var(--el-table-header-text-color) !important"
                      >录取分数</span
                    >
                  </template>
                </el-popover>
              </router-link>
            </template>
          </el-table-column>

          <el-table-column
            header-align="center"
            align="center"
            prop="zsjhs"
            label="招生计划数"
            width="90"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm2"
                placement="bottom"
              >
                <template #reference>
                  <el-span>招生计划数</el-span>
                </template>
              </el-popover>
            </template>
          </el-table-column>

          <el-table-column header-align="center" align="center" prop="dyzyl" label="第一志愿率">
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm3"
                placement="bottom"
              >
                <template #reference>
                  <el-span>第一志愿率</el-span>
                </template>
              </el-popover>
            </template>
          </el-table-column>

          <el-table-column
            header-align="center"
            align="center"
            prop="bdl"
            width="90"
            label="报到率"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm4"
                placement="bottom"
              >
                <template #reference>
                  <el-span>报到率</el-span>
                </template>
              </el-popover>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="专业认可度" header-align="center" align="center">
          <el-table-column
            header-align="center"
            align="center"
            prop="ysylzy"
            width="90"
            label="优势（一流）专业"
          >
            <template #header>
              <router-link
                to="ysylzy"
                @click="
                  handleAddTag({ path: '/home/ysylzy', name: 'ysylzy', title: '优势(一流)专业' })
                "
              >
                <el-popover
                  :width="zbsmwidth"
                  class="box-item"
                  title="说明"
                  :content="zbsm5"
                  placement="bottom"
                >
                  <template #reference>
                    <el-span style="color: var(--el-table-header-text-color) !important"
                      >优势（一流）专业</el-span
                    >
                  </template>
                </el-popover>
              </router-link>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="zzyqk"
            width="90"
            label="转专业情况"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm6"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="zzyqk"
                    @click="
                      handleAddTag({ path: '/home/zzyqk', name: 'zzyqk', title: '转专业情况' })
                    "
                    ><span style="color: var(--el-table-header-text-color) !important"
                      >转专业情况</span
                    ></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column header-align="center" align="center" prop="zymyd" width="90">
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm7"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="zhibiao"
                    @click="
                      handleAddTag({ path: '/home/zhibiao', name: 'zhibiao', title: '专业满意度' })
                    "
                    ><span style="color: #002b80">专业满意度</span></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table-column>

      <el-table-column label="培养过程" header-align="center" align="center">
        <el-table-column label="高层次人才" header-align="center" align="center">
          <el-table-column
            header-align="center"
            align="center"
            prop="gccch"
            width="90"
            label="高层次称号"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm8"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="gccch"
                    @click="
                      handleAddTag({ path: '/home/gccch', name: 'gccch', title: '高层次称号' })
                    "
                    ><span style="color: var(--el-table-header-text-color) !important"
                      >高层次称号</span
                    ></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="gcctd"
            width="90"
            label="高层次团队"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm9"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="gcctd"
                    @click="
                      handleAddTag({ path: '/home/gcctd', name: 'gcctd', title: '高层次团队' })
                    "
                    ><span style="color: var(--el-table-header-text-color) !important"
                      >高层次团队</span
                    ></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="师资队伍" header-align="center" align="center">
          <el-table-column
            header-align="center"
            align="center"
            prop="sljg"
            width="90"
            label="数量结构"
          >
            <template #header>
              <el-popover :width="zbsmwidth" class="box-item" title="说明" placement="bottom">
                <template #default>
                  <div style="white-space: pre-line">{{ zbsm10 }}</div>
                </template>

                <template #reference>
                  <span style="color: #7e2030">数量结构</span>
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="ssb"
            width="90"
            label="师生比"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm11"
                placement="bottom"
              >
                <template #reference>
                  <span style="color: #7e2030">师生比</span>
                </template>
              </el-popover>
            </template>
          </el-table-column>

          <el-table-column
            header-align="center"
            align="center"
            prop="jxsp"
            width="90"
            label="教学水平"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm12"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="jxsp"
                    @click="handleAddTag({ path: '/home/jxsp', name: 'jxsp', title: '教学水平' })"
                    ><span style="color: #7e2030">教学水平</span></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="kysp"
            width="90"
            label="科研水平"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm13"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="kysp"
                    @click="handleAddTag({ path: '/home/kysp', name: 'kysp', title: '科研水平' })"
                    ><span style="color: #7e2030">科研水平</span></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="资源配置" header-align="center" align="center">
          <el-table-column
            header-align="center"
            align="center"
            prop="syjx"
            width="90"
            label="专业实验教学校内场所情况"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm14"
                placement="bottom"
              >
                <template #reference>
                  <spean>专业实验教学校内场所情况</spean>
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="sxsjsxjdqk"
            width="90"
            label="实习实践实训基地情况"
          >
            <template #header>
              <el-popover :width="zbsmwidth" class="box-item" title="说明" placement="bottom">
                <template #default>
                  <div style="white-space: pre-line">{{ zbsm15 }}</div>
                </template>
                <template #reference>
                  <router-link
                    to="sxsjsxjdqk"
                    @click="
                      handleAddTag({
                        path: '/home/sxsjsxjdqk',
                        name: 'sxsjsxjdqk',
                        title: '实习实践实训基地情况',
                      })
                    "
                    ><span style="color: #7e2030">实习实践实训基地情况</span></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="课程质量" header-align="center" align="center">
          <el-table-column
            header-align="center"
            align="center"
            prop="ylkcjs"
            width="90"
            label="一流课程建设"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm16"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="ylkcjs"
                    @click="
                      handleAddTag({ path: '/home/ylkcjs', name: 'ylkcjs', title: '一流课程建设' })
                    "
                    ><span style="color: var(--el-table-header-text-color) !important"
                      >一流课程建设</span
                    ></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="cbjczl"
            width="90"
            label="出版教材质量"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm17"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="cbjczl"
                    @click="
                      handleAddTag({ path: '/home/cbjczl', name: 'cbjczl', title: '出版教材质量' })
                    "
                    ><span style="color: var(--el-table-header-text-color) !important"
                      >出版教材质量</span
                    ></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <!--
          <el-table-column header-align="center" align="center"
                           prop="zykcjxmyd" width="90"
                           label="专业课程教学满意度">
            <template #header>
              <span style="color: #002B80;">专业课程教学满意度</span>
            </template>
          </el-table-column>
          -->
          <el-table-column
            header-align="center"
            align="center"
            prop="xxhkcjs"
            width="90"
            label="信息化课程建设"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm18"
                placement="bottom"
              >
                <template #reference>
                  <span>信息化课程建设</span>
                </template>
              </el-popover>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table-column>

      <el-table-column label="学生发展与就业" header-align="center" align="center">
        <el-table-column label="学生成长" header-align="center" align="center">
          <!--
          <el-table-column header-align="center" align="center"
                           prop="zysy" width="90"
                           label="专业素养">

            <template #header>
              <router-link to="zysy" @click="handleAddTag({path: '/home/zysy',name: 'zysy',title: '专业素养'})"><span style="color: #002B80;">专业素养</span></router-link>
            </template>
          </el-table-column>
          <el-table-column header-align="center" align="center"
                           prop="tynl" width="90"
                           label="通用能力">
            <template #header>
              <router-link to="tynl" @click="handleAddTag({path: '/home/tynl',name: 'tynl',title: '通用能力'})"><span style="color: #002B80;">通用能力</span></router-link>
            </template>
          </el-table-column>
        -->
          <el-table-column
            header-align="center"
            align="center"
            prop="gyxljyhdcyqk"
            width="90"
            label="高影响力教育活动参与情况"
          >
            <template #header>
              <el-popover :width="zbsmwidth" class="box-item" title="说明" placement="bottom">
                <template #default>
                  <div style="white-space: pre-line">{{ zbsm19 }}</div>
                </template>
                <template #reference>
                  <router-link
                    to="gyxljyhdcyqk"
                    @click="
                      handleAddTag({
                        path: '/home/gyxljyhdcyqk',
                        name: 'gyxljyhdcyqk',
                        title: '高影响力教育活动参与情况',
                      })
                    "
                    ><span style="color: #7e2030">高影响力教育活动参与情况</span></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="xxcx"
            width="90"
            label="学习成效"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm20"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="xxcx"
                    @click="handleAddTag({ path: 'xxcx', name: '/home/xxcx', title: '学习成效' })"
                    ><span style="color: var(--el-table-header-text-color) !important"
                      >学习成效</span
                    ></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="lwcjhgl"
            width="90"
            label="论文抽检合格率"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm21"
                placement="bottom"
              >
                <template #reference>
                  <span>论文抽检合格率</span>
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="byzhxlqk"
            width="90"
            label="毕业综合训练情况"
          >
            <template #header>
              <el-popover :width="zbsmwidth" class="box-item" title="说明" placement="bottom">
                <template #default>
                  <div style="white-space: pre-line">{{ zbsm22 }}</div>
                </template>
                <template #reference>
                  <router-link
                    to="byzhxlqk"
                    @click="
                      handleAddTag({
                        path: '/home/byzhxlqk',
                        name: 'byzhxlqk',
                        title: '毕业综合训练情况',
                      })
                    "
                    ><span style="color: #7e2030">毕业综合训练情况</span></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column label="就业质量" header-align="center" align="center">
          <el-table-column
            header-align="center"
            align="center"
            prop="jyl"
            width="90"
            label="就业率"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm23"
                placement="bottom"
              >
                <template #reference>
                  <span>就业率</span>
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="kyl"
            width="90"
            label="考研率"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm24"
                placement="bottom"
              >
                <template #reference>
                  <span>考研率</span>
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="jyqx"
            width="90"
            label="就业去向"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm25"
                placement="bottom"
              >
                <template #reference>
                  <span>就业去向</span>
                </template>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="jyyzyxgd"
            width="90"
            label="就业与专业相关度"
          >
            <template #header>
              <el-popover
                :width="zbsmwidth"
                class="box-item"
                title="说明"
                :content="zbsm26"
                placement="bottom"
              >
                <template #reference>
                  <router-link
                    to="jyyzyxgd"
                    @click="
                      handleAddTag({
                        path: '/home/jyyzyxgd',
                        name: 'jyyzyxgd',
                        title: '就业与专业相关度',
                      })
                    "
                    ><span style="color: #002b80">就业与专业相关度</span></router-link
                  >
                </template>
              </el-popover>
            </template>
          </el-table-column> </el-table-column
        >`
      </el-table-column>
    </el-table>
  </div>

  <div class="row4">
    <el-button type="primary">当前有_{{ xxshu }}_个学校数据显示</el-button>
    <el-button type="primary" @click="getfzzspjf()"
      >当前_{{ xxshu }}_个学校发展指数平均分为_{{ fzzspjf11 }}_</el-button
    >
  </div>
</template>

<script setup>
import { watch, ref, onBeforeUnmount, onMounted, watchEffect } from 'vue'
import axios from 'axios'
import { useTagStore } from '@/stores/tags.js'
import { useDataStore } from '@/stores/choose.js'
import { ElLoading } from 'element-plus'
import router from '@/router/index.js'

// 定义指标说明数据
let zbsmwidth = ref('300px')
let zbsm000 = ref(
  '专业:如果一个学校有多个相同专业，则只计算其中一个在校内专业名称和专业名称相同的专业的指标数据。其他相同专业数据默认不显示',
)
let zbsm0 = ref(
  '发展指数:从26个指标得分中只取有效指标得分数据按权重相加，再除以有效指标数，计算平均分 \n 【发展指数 =  {相加（每一个指标得分*该指标设置的权重）} / 有效指标数】',
)
let zbsm00 = ref(
  '有效指标数:从26个指标数据中筛选出有效指标个数。\n 【有效指标数=遍历26个指标数据，如果该指标数据有值，则有效指标数+1，否则不计入有效指标数】',
) //比如如果A大小B专业学生没有填写专业满意度问卷的话，则该专业的有效指标数为25个。计算发展指数的时候，只拿去有效指标数据来计算平均分。 ')
let zbsm1 = ref('录取分数:专业的高考分数加权平均。')
let zbsm2 = ref(
  '招生计划数:该校该专业当年招生计划数 \n 【招生计划数=专业招生计划数,学校发布的数据为准】',
)
let zbsm3 = ref(
  '第一志愿率:第一志愿率=第一志愿录取人数/录取人数。\n 【 第一志愿率=该校该专业第一志愿录取人数/录取人数】',
)
let zbsm4 = ref('报到率 :报到率=报到人数/招录人数。')
let zbsm5 = ref('优势(一流)专业:由各优势（一流）专业组成')
let zbsm6 = ref(
  '转专业情况:（转出人数-转入人数）然后 以按官方专业代码归一化计算 。如果没有转入转出数据，则视为转出人数和转入人数均为0。',
)
let zbsm7 = ref('专业满意度: 问卷调查结果')
let zbsm8 = ref(
  '高层次称号: 查询该校该专业上课老师中有没有高层次人才，如果有，则按老师的高层次人才类型不同，给相应的分数。',
)
let zbsm9 = ref(
  '高层次团队: 查询该校该专业上课老师中有没有高层次团队负责人，如果有，则按老师的高层次团队类型不同，给相应的分数。  ',
)
let zbsm10 = ref(
  '数量结构: 该指标得分由专业教师承担教学情况子指标得分和专任教师数量及结构子指标得分的平均分得出的。 \n' +
    '1.专任教师数量及结构 :专任教师数量及结构=（专任教师总数、高级职称占比、教授占比、硕士博士占比、近五年新增教师、双师型、具有企业行业背景）加权计算。\n' +
    '2.专业教师承担教学情况 : =（专业课课程门数、专业教师授课比例、高级职称授课比例、教授授课比例、副教授授课比例）加权计算。',
)
let zbsm11 = ref('师生比: 师生比=(当前该校该专业学生数/教师数)结果以专业代码分组，然后归一化处理。')
let zbsm12 = ref('教学水平:从五个子指标得分中只取有效子指标得分数据计算平均分。\n ')
let zbsm13 = ref('科研水平:从四个子指标得分中只取有效子指标得分数据计算平均分。\n')
let zbsm14 = ref(
  '专业实验教学校内场所情况:专业实验教学校内场所情况=（基础实验室、专业实验室、校内实习场所、校内实训场所）根据数量、面积、设备台套数、设备值加权计算。（生均面积和生均仪器设备值）',
)
let zbsm15 = ref(
  '实习实训基地情况:从两个子指标得分中只取有效子指标得分数据计算平均分。\n ' +
    '1.省级及以上本科教学项目建设情况中相关基地情况加权计算。产学研合作项目...数量、级别等等.\n' +
    '2.实习实践实训基地情况=（校内外实习实践实训基地数量、当年接纳学生总人次）加权计算。',
)
let zbsm16 = ref(
  '一流课程建设:一流课程建设=省级及以上本科教学项目建设情况中相关课程情况加权计算。主要由线下一流课程、线上线下混合式一流课程、社会实践一流课程、精品在线开放课程（线上一流课程）、来华留学品牌课程、虚拟仿真实验教学项目（包含虚拟仿真实验教学一流课程的项目 ）、课程思政示范课程组成。',
)
let zbsm17 = ref('出版教材质量:出版教材质量=教师作为第一作者公开出版，获得省部级以上奖项加权计算.')
let zbsm18 = ref(
  '信息化课程建设:慕课、人工智能、大模型相关形式的课程=开课门数加权计算。主要由精品在线开放课程（特指由国家或省级教育行政主管部门专项评选认定的相关课程）、MOOC（面向社会开放的大规模网络课程）、SPOC（针对校内特定群体进行的小规模网络课程）、在线教学英文版国际平台上线课程组成。',
)
let zbsm19 = ref(
  '高影响力教育活动参与情况:从三个子指标得分中只取有效子指标得分数据计算平均分。\n ' +
    '1.参加创新创业训练计划=（大学生创新训练项目、教师科研）根据总数、国家级、省部级加权计算。\n ' +
    '2.参加教师科研情况=项目数、学生数加权计算。\n ' +
    '3.本科生交流情况=交流次数和人数加权计算。',
)
let zbsm20 = ref(
  '学习成效:学习成效=发表学术论文、创作、表演的代表性作品、专业（著作权）、各类竞赛获奖、艺术类专业比赛获奖加权计算。',
)
let zbsm21 = ref('论文抽检合格率:')
let zbsm22 = ref(
  '毕业综合训练情况:从两个子指标得分中只取有效子指标得分数据计算平均分。\n' +
    '1.毕业综合训练情况=来源（教师课题、社会实践）根据不同学科进行加权计算。\n' +
    '2.教师指导学生毕业综合训练情况=学生与指导教师比。',
)
let zbsm23 = ref('就业率:就业率=就业学生/毕业学生总数。')
let zbsm24 = ref('考研率:考研率=考研学生/毕业学生总数。')
let zbsm25 = ref('就业去向:就业去向=省内、省外')
let zbsm26 = ref('就业与专业相关度:问卷数据')

// 定义数据
let tableData = ref([
  {
    school: '',
    major: '',
    lqfs: '',
    dyzyl: '',
    bdl: '',
    ysylzy: '',
    zzyqk: '',
    zymyd: '',
    gccch: '',
    gcctd: '',
    sljg: '',
    jxsp: '',
    kysp: '',
    syjx: '',
    sxsjsxjdqk: '',
    ylkcjs: '',
    cbjczl: '',
    ssb: '',
    xxhkcjs: '',
    zsjhs: '',
    tynl: '',
    gyxljyhdcyqk: '',
    xxcx: '',
    lwcjhgl: '',
    byzhxlqk: '',
    jyl: '',
    kyl: '',
    jyqx: '',
    jyyzyxgd: '',
    fzzs: '',
    yxzbs: '',
    fzzspjf: '',
  },
])
let xxshu = ref(0)
let fzzspjf11 = ref(0.0)

const props = defineProps({
  selectedOptions: {
    type: Array,
    default: () => [],
  },
  loading: {
    type: Boolean,
    default: false,
  },
})
const emit = defineEmits(['data-loaded'])
const internalLoading = ref(false)

const getData = async (options) => {
  if (!options || options.length === 0) return

  const loadingService = ElLoading.service({
    lock: true,
    text: '正在拼命加载中...',
    background: 'rgba(0, 0, 0, 0.7)',
  })

  try {
    internalLoading.value = true

    const response = await axios({
      url: '/scores',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json;charset=UTF-8',
      },
      data: options.map((item) => ({
        school: item[2],
        major: item[1],
      })),
    })

    const flage = -88

    tableData.value = response.data.map((item, index) => ({
      ...item,
      school: item.xxmc || '未开设此专业',
      major: item.xnzymc || '未开设此专业',
      lqfs: item.lqfs === flage ? '*' : item.lqfs,
      dyzyl: item.dyzyl === flage ? '*' : item.dyzyl,
      bdl: item.bdl === flage ? '*' : item.bdl,
      ysylzy: item.ysylzy === flage ? '*' : item.ysylzy,
      yszy: item.yszy === flage ? '*' : item.yszy,
      zzyqk: item.zzyqk === flage ? '*' : item.zzyqk,
      zymyd: item.zymyd === flage ? '*' : item.zymyd,
      gccch: item.gccch === flage ? '*' : item.gccch,
      gcctd: item.gcctd === flage ? '*' : item.gcctd,
      sljg: item.sljg === flage ? '*' : item.sljg,
      jxsp: item.jxsp === flage ? '*' : item.jxsp,
      kysp: item.kysp === flage ? '*' : item.kysp,
      syjx: item.syjx === flage ? '*' : item.syjx,
      sxsjsxjdqk: item.sxsjsxjdqk === flage ? '*' : item.sxsjsxjdqk,
      ssb: item.ssb === flage ? '*' : item.ssb,
      xxhkcjs: item.xxhkcjs === flage ? '*' : item.xxhkcjs,
      zysy: item.zysy === flage ? '*' : item.zysy,
      tynl: item.tynl === flage ? '*' : item.tynl,
      gyxljyhdcyqk: item.gyxljyhdcyqk === flage ? '*' : item.gyxljyhdcyqk,
      xxcx: item.xxcx === flage ? '*' : item.xxcx,
      lwcjhgl: item.lwcjhgl === flage ? '*' : item.lwcjhgl,
      byzhxlqk: item.byzhxlqk === flage ? '*' : item.byzhxlqk,
      ylkcjs: item.ylkcjs === flage ? '*' : item.ylkcjs,
      jyl: item.jyl === flage ? '*' : item.jyl,
      kyl: item.kyl === flage ? '*' : item.kyl,
      jyqx: item.jyqx === flage ? '*' : item.jyqx,
      jyyzyxgd: item.jyyzyxgd === flage ? '*' : item.jyyzyxgd,
      fzzs: item.fzzs === flage ? '*' : item.fzzs,
      yxzbs: item.yxzbs === flage ? '*' : item.yxzbs,
      zsjhs: item.zsjhs === flage ? '*' : item.zsjhs,
      cbjczl: item.cbjczl === flage ? '*' : item.cbjczl,
      fzzspjf: (item.fzzs / item.yxzbs).toFixed(5),
    }))

    function filterByMaxYxzbs(data) {
      return Object.values(
        data.reduce((acc, curr) => {
          const key = curr.xxdm // 按学校代码分组
          if (!acc[key] || curr.yxzbs > acc[key].yxzbs) {
            acc[key] = curr // 保留当前最大 yxzbs 的记录
          }
          return acc
        }, {}),
      )
    }

    // 使用示例
    const filteredData = filterByMaxYxzbs(tableData.value)
    console.log(filteredData)

    //tableData.value = filteredData

    //以学校名称和专业名称排序
    tableData.value.sort((a, b) => {
      if (a.fzzspjf < b.fzzspjf) {
        return 1
      } else {
        return -1
      }
    })

    getfzzspjf()

    console.log(response.data)
    dataStore.setSelectedData(response.data)
    console.log('tableData', tableData.value)
    emit('data-loaded')

    loadingService.close()
  } catch (error) {
    loadingService.close()
    console.error('请求失败:', error)
    // 可以在这里添加错误处理逻辑，如显示错误提示
  } finally {
    internalLoading.value = false
    loadingService.close()
  }
}

function getfzzspjf() {
  xxshu.value = tableData.value.length
  let aa = 0
  tableData.value.forEach((item) => {
    const num = parseFloat(item.fzzspjf)
    aa += num
  })
  console.log(aa)
  aa = aa / xxshu.value
  fzzspjf11.value = aa.toFixed(5)
}

// // 深度监听selectedOptions变化
// watch(
//   () => props.selectedOptions,
//   (newVal, oldVal) => {
//     if (newVal && newVal.length > 0 && JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
//       getData(newVal);
//     }
//   },
//   { deep: true }
// );
// 监听 selectedOptions 变化
const dataStore = useDataStore()
watch(
  () => dataStore.selectedOptions,
  (newOptions) => {
    if (newOptions.length > 0) {
      getData(dataStore.selectedOptions)
    }
  },
)
watchEffect(() => {
  // 当 dataStore.specificData 变化时自动运行
  if (dataStore.selectedOptions) {
    console.log('重新加载数据')
    getData(dataStore.selectedOptions)
  }
})
defineExpose({ getData })

const tagStore = useTagStore()
const handleAddTag = (tagInfo) => {
  tagStore.addTag({
    path: tagInfo.path,
    name: tagInfo.name,
    meta: { title: tagInfo.title },
  })
}
onMounted(() => {
  // 恢复数据
  const savedData = localStorage.getItem('tempTableData')
  if (savedData) {
    tableData.value = JSON.parse(savedData)
  }

  // 监听页面刷新，刷新时清空数据
  window.addEventListener('beforeunload', clearTempData)
})

onBeforeUnmount(() => {
  // 组件卸载时保存数据（路由跳转）
  localStorage.setItem('tempTableData', JSON.stringify(tableData.value))

  // 移除监听，避免内存泄漏
  window.removeEventListener('beforeunload', clearTempData)
})

// 清空 localStorage 的辅助函数
function clearTempData() {
  localStorage.removeItem('tempTableData')
}

function dowenloadexel() {
  const url = 'http://localhost:8081/export' // 假设后端运行在 8080 端口
  console.log('发出请求了:' + url)
  const jwt_token11 = localStorage.getItem('jwt_token')
  // 使用 axios 发起请求
  //--------------------------
  axios({
    url: url,
    method: 'GET',
    headers: { Authorization: 'Bearer ' + jwt_token11 },
    responseType: 'blob', // 指定响应类型为 blob，用于处理二进制文件
  })
    .then((response) => {
      // 解析文件名（兼容不同浏览器响应头大小写）
      const contentDisposition =
        response.headers['content-disposition'] || response.headers['Content-Disposition']
      let fileName = 'Model.xlsx'

      // 增强型文件名解析（支持RFC 5987编码）
      if (contentDisposition) {
        const filenameRegex = /filename\*?=['"]?(?:UTF-\d['"]*)?([^;\r\n"']*)['"]?/i
        const matches = contentDisposition.match(filenameRegex)

        if (matches && matches[1]) {
          fileName = decodeURIComponent(matches[1].trim())
            .replace(/['"]/g, '') // 去除残留引号
            .replace(/\s+/g, '_') // 空格转下划线
        }
      }

      // 创建Blob对象
      const blob = new Blob([response.data], {
        type:
          response.headers['content-type'] ||
          'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      })

      // 创建下载链接
      const downloadUrl = window.URL.createObjectURL(blob)
      const link = document.createElement('a')
      link.href = downloadUrl
      link.download = fileName
      link.style.display = 'none'

      // 触发下载
      document.body.appendChild(link)
      link.click()

      // 资源清理
      setTimeout(() => {
        document.body.removeChild(link)
        window.URL.revokeObjectURL(downloadUrl)
        console.log('已释放下载资源:', fileName)
      }, 100)
    })
    .catch((error) => {
      console.error('文件下载失败:', {
        status: error.response?.status,
        message: error.message,
      })
      // 处理服务端生成的临时文件清理失败场景
      if (error.response?.status === 500) {
        alert('服务器文件生成失败，请重试')
      }
    })
  console.log('发出请求了:' + url)
}

function quanzhong() {
  router.push({ path: '/home/quanzhong' })
  tagStore.addTag({
    path: '/home/quanzhong',
    name: 'quanzhong',
    meta: { title: '权重' },
  })
}
</script>
